package de.lindenvalley.sevmob;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.util.Log;

/**
 * After install SDK on the device, it'll send Broadcast receiver with referrer
 * @author Lindenvalley GmbH
 *
 */
class ApplicationReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		
		String referrer = "";
		   Bundle extras = intent.getExtras();
		   if(extras != null){
		      referrer = extras.getString("referrer");
		      SharedPreferences preferences = context.getSharedPreferences(context.getString(R.string.prefs_fileName), Context.MODE_PRIVATE);
		      
		      SevMobTracker tracker = new SevMobTracker(context);
		      String deviceId = tracker.trackerInstall(referrer);
		      
		      Editor editor = preferences.edit();
		      editor.putString(context.getString(R.string.prefs_referrer), referrer);
		      editor.putString(context.getString(R.string.prefs_deviceId), deviceId);
		      
		      editor.commit();
		      

		   }

		   Log.i("REFERRER ------------------=========================--------------------","Referer is: "+referrer);

	}

}
